package com.xrf;


import com.sun.org.slf4j.internal.LoggerFactory;

import java.util.logging.Logger;

@Api(tags = "获取考勤业务编码API")
@RestController()
@RequestMapping("/seq")
public class BusinessSeqController {
    private static Logger logger = LoggerFactory.getLogger(BusinessSeqController.class);
    
    @Autowired
    private BusinessSeqService businessSeqServiceImpl;
    
    @GetMapping("/next")
    public ResultView selectNextValue(String type, String key) {
        ResultView view = new ResultView(EnumCode.SUCCESS);
        try {
            String[] next = businessSeqServiceImpl.nextValuePlus(type, key, 1);
            if (next == null || next.length == 0) {
                view.setMsg("该考勤业务或考勤业务编码不存在");
                view.setCode(EnumCode.SUCCESS_204);
                return view;
            }
            view.setData(next[0]);
        } catch (Exception e) {
            view.setMsg("获取下一个考勤业务编码-错误");
            view.setCode(EnumCode.ERROR_9999);
        } finally {
            logger.info("获取下一个考勤业务编码-结束");
        }
        return view;
    }
    
    @GetMapping("/plus-next")
    public ResultView selectNextValuePlus(String type, String key, Integer length, HttpServletRequest request) {
        ResultView view = new ResultView(EnumCode.SUCCESS);
        try {
            String[] next = businessSeqServiceImpl.nextValuePlus(type, key, length);
            if (next == null || next.length == 0) {
                view.setMsg("该考勤业务或考勤业务编码不存在");
                view.setCode(EnumCode.SUCCESS_204);
                return view;
            }
            view.setData(next);
        } catch (Exception e) {
            view.setMsg("获取下一个考勤业务编码-错误");
            view.setCode(EnumCode.ERROR_9999);
        } finally {
            logger.info("获取下一个考勤业务编码-结束");
        }
        return view;
    }
}